<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\EbPolicyApplication\model;

use app\policyMatching\model\PolicyMatching;
use plugin\saiadmin\basic\BaseModel;

/**
 * 申报列表模型
 */
class EbPolicyApplication extends BaseModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_policy_application';

    
    /**
     * 公司名称 搜索
     */
    public function searchCompanyNameAttr($query, $value)
    {
        $query->where('company_name', 'like', '%'.$value.'%');
    }
    
    /**
     * 姓名 搜索
     */
    public function searchNameAttr($query, $value)
    {
        $query->where('name', 'like', '%'.$value.'%');
    }
    
    /**
     * 申报时间 搜索
     */
    public function searchCreateTimeAttr($query, $value)
    {
        $query->whereTime('create_time', 'between', $value);
    }
    /**
     * 政策名称 搜索
     */
    public function searchPolicyTitleAttr($query, $value)
    {
        $query->where('matching_id', 'in', PolicyMatching::where('policy_title', 'like', '%'.$value.'%')->column('matching_id'));
    }

    /**
     * 关联模型PolicyMatching
     */
    public function PolicyMatching()
    {
        return $this->hasOne(PolicyMatching::class, 'matching_id', 'matching_id');
    }


}
